package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.mapper.SignMapper;
import cn.wolfcode.trip.base.service.ISignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class SignServiceImpl implements ISignService {
    @Autowired
    private SignMapper signMapper;
    @Override
    public List<String> get(Long userId) {
        List<String> signs = signMapper.get(userId);
        return signs;
    }

    @Override
    public Sign getSign(Long userId) {
        return signMapper.getSign(userId);
    }

    @Override
    public void setSign(Long userId) {
        int count=signMapper.getSignTime(userId);
        Sign sign = signMapper.getSign(userId);
        sign.setSign_time(new Date());
        if (count<2){
            sign.setSigns(sign.getSigns()+1);
            if (sign.getSigns()>8){
                sign.setIntegral(sign.getIntegral()+50);
            }else {
                sign.setIntegral(sign.getIntegral()+10);
            }
        }else {
            sign.setSigns(1);
            sign.setIntegral(sign.getIntegral()+10);
        }
        signMapper.insert(sign);
    }
}
